<?php
/**
 * Created by PhpStorm.
 * User: sks
 * Date: 2015/12/15
 * Time: 13:49
 */

class Involved_ShopModel extends BaseModel{

    protected $table = 'category';

    /**
     *分类列表
     * @return mixed
     */
    public function CatesList()
    {
        return  DB::table($this->table)
               ->where('fid',0)
                ->where('statue',1)
                ->get();
    }
    public function SelectCategory($id,$fids){
        return DB::table($this->table)
            ->select('cate_name','c_id','fid')
            ->where('fid',$id)
            ->where('statue',1)
            ->skip(0)
            ->take(3)
            ->get();
    }

    /**
     *父级分类
     * @return mixed
     */
    public function CatListfa()
    {
        return  DB::table($this->table)
            ->where('fid',0)
            ->where('statue',1)
            ->get();
    }
    /**
     *是否存在ID
     * @return mixed
     */
    public function CatFirst($id){
          $data=DB::table($this->table)
            ->where('c_id',$id)
              ->where('statue',1)
            ->first();
        //dd($data);
       return $data;
    }
    /**
     *查询是子级还是父级
     * @return mixed
     */
    public function FatherCategory($id){
        $data=DB::table($this->table)
            ->select('fid')
            ->where('c_id',$id)
            ->where('statue',1)
            ->first();
        //dd($data);
        return $data;
    }


    /**
     *查询是父级下面的子级
     * @return mixed
     */
    public function ParpentCategory($id){
        $data=DB::table($this->table)
            ->select('c_id')
            ->where('fid',$id)
            ->where('statue',1)
            ->get();
        //dd($data);
        return $data;
    }
    /**
     *查询是父级下面的子级
     * @return mixed
     */
    public function SelectCategorys($id){
        $da= DB::table($this->table)
            ->select('cate_name','c_id')
            ->where('fid',$id)
            ->where('statue',1)
            ->get();
//        dd($da);
       return $da;
    }
    /**
    *1F木材
     */
    public function MuCaiList()
    {
        return  DB::table($this->table)
            ->where('fid',0)
            ->where('statue',1)
            ->get();
    }
    /**
     *商家
     */
    public function BusinList($id,$fids)
    {
        return  DB::table($this->table)
           ->select('category.cate_name','shop_product.product_name','shop_product.img1','shop_business.logo','category.c_id','category.fid','shop_product.product_id','shop_product.business_id')
            ->LeftJoin('shop_product','category.c_id','=','shop_product.sort')
            ->LeftJoin('shop_business','shop_product.business_id','=','shop_business.business_id')
            ->where('statue',1)
            //->where('fid',$id)
            ->where('fid',$id)
            //->orWhere('c_id',$fids)
            ->skip(0)
            ->take(4)
            ->where('category.fid','>','0')
            ->get();
    }

//    public function SelectCategorys($id){
//        $da= DB::table($this->table)
//            ->select('cate_name','c_id')
//            ->where('fid',$id)
//            ->where('statue',1)
//            ->get();
////        dd($da);
//        return $da;
//    }

    /**
     *查询是父级下面的子级
     * @return mixed
     */
    public function SelectCategoryes($id){
        $da= DB::table($this->table)
            ->select('cate_name','c_id','fid')
            ->where('fid',$id)
            ->where('statue',1)
            ->skip(0)
            ->take(6)
            ->get();
//        dd($da);
        return $da;
    }


    /**
     * 分类
     * @param $c_id
     * @return array
     */
    public function YptShopListSort($c_id)
    {
       global $temp;
        $db1 =   DB::table($this->table);
        $data = $db1
            ->select('c_id')
            ->where('fid',$c_id)
            ->get();

        $data = json_encode($data);
        $data = json_decode($data,true);

        if(empty($data))
        {
            return $c_id.',';
        }

        if(!empty($data)){
            foreach($data as $key => $val)
            {
                $temp.=$val['c_id'].',';
                $this->YptShopListSort($val['c_id']);
            }

        }
        return $temp;

    }

 

}